
function initQueryForm(region){
	var form = new Ext.FormPanel({
        frame: true,
        labelAlign: 'right',
        labelWidth: 85,
        split:true,
        height:50,
        jsonSubmit:true,
        scrollable:true,
        autoScroll:true,
        region:region,
        id:'queryForm',
        closable:true,
        waitMsgTarget: true,
        items: [{
        	xtype:'compositefield',
            defaults:{
            	xtype:'textfield'
            },
        	items:[{xtype:'label',text:"编号"},
        		{name: 'id',xtype:'textfield', editable : false,
        			width:120,readOnly:true},
        			{xtype:'label',text:"名称"},
                {	
                	name: 'name',
                	allowBlank:false,
                	editable:false,
                	width:200,
                	xtype:'textfield'
                },{xtype:'label',text:"启运日期"},{	
                	allowBlank:false,
                	name:"startDate",
                	editable:false,
                	width:200,
                	xtype:'datefield'
                },{xtype:'label',text:'-'},{
                	allowBlank:false,
                	editable:false,
                	width:200,
                	name:'endDate',
                	xtype:'datefield'
                },
                {xtype:'label',text:"状态"},
                {	
                	hiddenName: 'flag',
                	name: 'flag',
                	allowBlank:false,
                	editable:false,
                	width:200,
                	value:"1",
                	xtype:'combo',
                	store : new Ext.data.ArrayStore({
            	        fields: [
            	 	            'SID',
            	 	            'TEXT'
            	 	        ],
            	 	        data: [
            	 	            ["1", '有效'],
            	                 ["-1", '无效']
            	             ]	
            	 	    }), 
       			 	triggerAction:'all',
                    displayField : 'TEXT',  
                    valueField : 'SID',  
                    mode : 'local', 
                    editable : false
                },
        		{
        			xtype:"button",
        			text:"查询",
        			handler:function(){
        				var grid=Ext.getCmp('orderGrid'),store=grid.store,
        				baseParams=store.baseParams,form=Ext.getCmp('queryForm').getForm();
        				baseParams["name"]=form.findField("name").getValue();
        				baseParams["startDate"]=form.findField("startDate").getValue();
        				baseParams["endDate"]=form.findField("endDate").getValue();
        				baseParams["flag"]=form.findField("flag").getValue();
        				store.reload();
        			}
        		}
        	]
        }]
 });
	return form;
	
}
function initOrderGridPanel(region){
	var selModel=new Ext.grid.RowSelectionModel();
	var column= new Ext.grid.ColumnModel({
        columns: [
				{ header: '编号', dataIndex: 'id', sortable: true,hidden:true},
				{ header: '名称', dataIndex: 'name', sortable: true },
				{ header: '品牌', dataIndex: 'brand', sortable: true },
				{ header: '启运日期', dataIndex: 'startDate', sortable: true },
				{ header: '到达时间', dataIndex: 'endDate', sortable: true }
        ]
    });
	  
	  var store = new Ext.data.Store({
	        reader: new Ext.data.JsonReader({
	    		fields    : [{name:'id'},{name:'name'},{name:'fid'},{name:'brand'},{name:'startDate'},{name:"endDate"}],
	    		root : 'itemList', totalProperty : 'pageInfo.total'
			}),
			proxy:new Ext.data.RestProxy({url:"./../order/list"}),
			autoLoad:true,
			baseParams:{name":"","startDate":"","endDate":"","flag":1,'pageInfo.start':0,"pageInfo.limit":20,'sortInfo.field':"id",'sortInfo.direct':"asc"},
			paramNames: {start:'pageInfo.start',limit:'pageInfo.limit',sort:'sortInfo.field',dir:'sortInfo.direct'}
		});
	  var tbars = new Ext.Toolbar({items: [
	                          	         {text:"新增", iconCls:"icon-submit",handler:function(){
	                          	        	
	                          	         }},
	                          	         {text:"刷新", iconCls:"icon-reload",handler:function(){
	                          	        	store.reload();
	                          	         }}
	                          	  ]});
	  var conf = {xtype:'paging',pageSize:20,displayInfo:true,autoWidth:true};
      conf.autoWidth=true;
      conf.displayMsg='当前显示第<font color="red">{0}~{1}</font>条,总数: <font color="red">{2}</font> 条.';
      conf.emptyMsg= "数据记录为空";
      conf.store=store;
	  var grid= new Ext.grid.GridPanel({
          tbar:tbars,
          id:'orderGrid',
          split:true,
          store: store,
          region:region,
          colModel: column,
          selModel:selModel,
          bbar:Ext.create(conf),
          viewConfig:{forceFit:true}
      });
	  return grid;
}

Ext.onReady(function() {
	Ext.QuickTips.init();
	var queryForm=initQueryForm('north');
	var orderList=initOrderGridPanel('center');
	new Ext.Viewport({
		width : 900,
		height : document.documentElement.clientHeight - 10,
		renderTo : 'container4',
		layout : 'border',
		items : [queryForm,orderList]
	});
});